WWL.splitpane = function ( name )
{
	var spane = new WWL ( 'splitpane', name );

	spane.mode = "H";

	spane.to_string = function ()
	{
		var s = '';

		s = '<div class="wwl_splitpane" id="' + this.id + '"><table class="table" border="1" width="100%" height="300" id="' + this.id + ':table"><tr>';

		if ( this.mode == 'H' )
		{
			s += '<td class="pane" id="' + this.id + ':box:1"></td>';
			s += '<td class="v_hanlde" id="' + this.id + ':handle" ' + this.mk_events ( "WWL.evt(event,%(OBJ)s,'%(EVENT_NAME)s')" ) + '></td>';
			s += '<td class="pane" id="' + this.id + ':box:2"></td>';

		} else  {
			s += '<td class="pane" id="' + this.id + ':box:1"></td></tr>';
			s += '<tr><td class="h_hanlde" id="' + this.id + ':handle" ' + this.mk_events () + '></td></tr>';
			s += '<tr><td class="pane" id="' + this.id + ':box:2"></td>';
		}

		s += '</tr></table></div>';

		/*
		s = '<div class="wwl_' + this.type + '" id="' + this.id + '"'; //>';
		s += this.mk_events ();
		s += '><div id="' + this.id + ':content" ';

		if ( this.tooltip ) s += ' title="' + this.tooltip + '"';


                s += ' class="' + WWL.mk_class_str ( this, ( this._is_disabled ? "disabled" : null ) ) + '">';
		s += this.label;
                s += '</div></div>';
		*/

		return s;
	};

	spane._int_events = {};

	spane._int_events [ 'over' ]     = function ( widget, div ) { };
	spane._int_events [ 'btn_down' ] = function ( widget, div, evt ) 
	{ 
		widget._is_moving = true;
		widget._screen_x  = evt.screenX;
		widget._screen_y  = evt.screenY;
		widget._dest =  $( widget.id + ":box:1" );
		widget._start_width = widget._dest.clientWidth;
		widget._start_height = widget._dest.clientHeight;

		widget._m_move = function ( evt ) { spane._mouse_move ( evt ); };
		widget._m_up = function ( evt ) { spane._mouse_up ( evt ); };

		liwe.events.add ( window, "mousemove", widget._m_move, false );
		liwe.events.add ( window, "mouseup", widget._m_up, false );
	};

	// spane._int_events [ 'but_up' ]   = function ( widget, div ) { };
	spane._int_events [ 'out' ]      = function ( widget, div ) { };

	spane._mouse_move = function ( evt )
	{
		if ( ! this._is_moving ) return;

		evt = evt || window.event;

		var sx = evt.screenX;
		var sy = evt.screenY;

		var dx = this._screen_x - sx;
		var dy = this._screen_y - sy;

		if ( this.mode == "H" )
			this._dest.style.width = this._start_width - dx + "px";
		else
			this._dest.style.height = this._start_height - dy + "px";

	};

	spane._mouse_up = function ( e )
	{
		this._is_moving = false;

		console.debug ( "FINE" );

		liwe.events.del ( window, "mousemove", spane._m_move );
		liwe.events.del ( window, "mouseup", spane._m_up );
	};

	return spane;
};

WWL.splitpane.get_instance = function ( instance_name )
{
	return WWL.get_instance ( "splitpane", instance_name );
};

// This is an internal function for splitpane class only
WWL.splitpane._set_class = function ( widget, div, class_name ) 
{ 
	div.firstChild.className = WWL.mk_class_str ( widget, class_name );
};
